#pragma once
#include <sstream>
#include <string>
#include <mutex>
#include <vector>
#include <thread>

#include <boost/log/core.hpp>
#include <boost/log/trivial.hpp>
#include <boost/log/expressions.hpp>

#include <boost/log/sinks.hpp>
#include <boost/log/sinks/sync_frontend.hpp>
#include <boost/log/sinks/text_ostream_backend.hpp>
#include <boost/log/utility/setup/file.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
//#include <boost/log/utility/manipulators/add_value.hpp>

#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>

#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/ini_parser.hpp>

#define WAITFOR_DATA 30000
#define WEBSOCKET_INTERVAL 200
#define SENSOR_ID_BASE 100
#define OFFSET_OF(type, member) ((size_t)&(((type *)0)->member))

extern boost::property_tree::ptree settings;
template<typename T> std::string serilize(const std::vector<T>& vec){
    std::stringstream ss;
    for (T num : vec) ss << "0x" << std::hex<< num << ",";
    return ss.str();
}
template<typename T> std::vector<unsigned char> data2uchar(T value){
    std::vector<unsigned char> data(sizeof(T),0);
    memcpy(&data[0],&value,data.size());
    return data;
}
static std::vector<unsigned char> data2uchar(std::string value,size_t size){
    std::vector<unsigned char> data(size,0);
    memcpy(&data[0],value.c_str(),value.size());
    return data;
}
void append(std::vector<unsigned char>& dest,const std::vector<unsigned char>& src);
void rappend(std::vector<unsigned char>& dest,const std::vector<unsigned char>& src);
void append(std::vector<unsigned char>& dest,const std::vector<unsigned char>& src, size_t len);
void rappend(std::vector<unsigned char>& dest,const std::vector<unsigned char>& src, size_t len);
unsigned char bitcombine(std::vector<int64_t>::iterator its,std::vector<int64_t>::iterator ite);
std::vector<unsigned char> bitsplit(std::vector<int64_t>&item, int len);
std::vector<unsigned char> config_parse(std::string label,std::string stext, int len);

void init_binary_log(std::string filename, int time, size_t max_size);
void set_thread_priority(std::thread& t, int priority);